package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageResult query(QueryObject qo) {
        int totalCount = departmentMapper.queryForCount(qo);
        if (totalCount == 0) {
            return new PageResult();
        }

        List<Department> list = departmentMapper.queryForList(qo);
        return new PageResult(totalCount, list);
    }

    @Override
    public int insert(Department entity) {

        return departmentMapper.insert(entity);
    }

    @Override
    public Department selectByPrimaryKey(Long id) {

        return departmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Department> selectAll() {
        return departmentMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Department entity) {

        return departmentMapper.updateByPrimaryKey(entity);
    }

    //修改部门状态
    @Override
    public int updateState(Long id) {
        return departmentMapper.updateState(id, Department.STATE_LOCK);
    }
}
